home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Misc / emu / p-interp.lha / p-interp-0.5 / rexx.c < prev    next >
C/C++ Source or Header  |  2002-04-25  |  3KB  |  95 lines

  1. /*
  2. ** C2Rexx.c  -- by Bryan Ewert  --  02 Jun 1996
  3. ** Amiga Users of Calgary OOPSIG  --  Calgary, Alberta, Canada
  4. **
  5. ** Sends the ARexx command "EXECUTE" to p-interp's
  6. ** Rexx port "TURTLESERVER"
  7. */
  8.  
  9. /*
  10. ** Based on code in:
  11. **
  12. **   fancydemo.c - A fancy rexx host that can send and receive messages.
  13. **   Author - Gary Samad & Bill Hawes
  14. **   This is truly Public Domain!!
  15. */
  16. #include "rexx.h"
  17.  
  18. /******** This is the REXX stuff ********/
  19. struct MsgPort *setup_rexx_port(void)
  20. {
  21.    struct MsgPort *the_port;
  22. return FindPort(TURTLE_HOST_NAME);
  23.    /* Disable multitasking so a port won't (dis)appear unexpectedly */
  24.    Forbid();
  25.    /* look for someone else that looks just like us! */
  26.    if (FindPort(HOST_PORT_NAME))
  27.    {
  28.      Permit();
  29.      printf("A public port called '%s' already exists!\n",HOST_PORT_NAME);
  30.      return(NULL);
  31.    }
  32.    /* allocate the port */
  33.    the_port = CreatePort(HOST_PORT_NAME,0L);
  34.    /* We're done here -- re-enable multitasking */
  35.    Permit();
  36.    /* Inform the application of our new port */
  37.    return(the_port);
  38. }
  39.  
  40. void shutdown_rexx_port(struct MsgPort *rexx_port)
  41. {
  42.    DeletePort(rexx_port);
  43. }
  44.  
  45. int send_rexx_command(char *buff)
  46. {
  47.    struct MsgPort *rexxport;      /* this will be rexx's port */
  48.    struct RexxMsg *rexx_command_message;   /* this is the message */
  49.    /* lock things temporarily */
  50.    Forbid();
  51.    /* if rexx is not active, just return NOTOK */
  52.    if ((rexxport = FindPort(TURTLE_HOST_NAME)) == NULL)
  53.    {
  54.      Permit();
  55.      return(NOTOK);
  56.    }
  57.    /* allocate a message packet for our command */
  58.    /* note that this is a very important call.  Much flexibility is */
  59.    /* available to you here by using multiple host port names, etc. */
  60.    if (NULL == (rexx_command_message = CreateRexxMsg(rexx_port,
  61. REXX_EXTENSION, rexx_port->mp_Node.ln_Name)))
  62.    {
  63.      Permit();
  64.      return(NOTOK);
  65.    }
  66.    /* create an argument string and install it in the message */
  67.    if (NULL == (rexx_command_message->rm_Args[0] = CreateArgstring(buff,
  68. strlen(buff))))
  69.    {
  70.      DeleteRexxMsg(rexx_command_message);
  71.      Permit();
  72.      return(NOTOK);
  73.    }
  74.    /* tell rexx that this is a COMMAND, not a FUNCTION, etc. */
  75.    rexx_command_message->rm_Action = RXCOMM;
  76.    /* and now the EASY part! */
  77.    PutMsg(rexxport, (struct Message *) rexx_command_message);
  78.    /* we're done hogging */
  79.    Permit();
  80.    printf("Message sent:\n");
  81.    printf("CommAddr: %s\n", rexx_command_message->rm_CommAddr);
  82.    printf("FileExt: %s\n", rexx_command_message->rm_FileExt);
  83.    printf("Arg: %s\n", rexx_command_message->rm_Args[0]);
  84.    /* successful, finally... */
  85.    return(OK);
  86. }
  87.  
  88. void free_rexx_command(struct RexxMsg *rexxmessage)
  89. {
  90.    /* delete the argument that we originally sent */
  91.    DeleteArgstring(rexxmessage->rm_Args[0]);
  92.    /* delete the extended message */
  93.    DeleteRexxMsg(rexxmessage);
  94. }
  95.